package com.xyht.sca_s.student_manage_system.modules.student_difficulty.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.student_difficulty.entity.req.SmsStudentDifficultyApplyReq;
import com.xyht.sca_s.student_manage_system.modules.student_difficulty.service.SmsStudentDifficultyApplyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 家庭经济困难认定申请表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-03-01
 */
@RestController
@RequestMapping("/difficulty/apply")
@SecretBody
public class SmsStudentDifficultyApplyController {
    @Autowired
    private SmsStudentDifficultyApplyService smsStudentDifficultyApplyService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "家庭经济困难学生认定申请提交")
    @PostMapping("/submit")
    public ResponseResult submitDifficultyApply(@RequestBody SmsStudentDifficultyApplyReq smsStudentDifficultyTaskReq,
                                               HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentDifficultyApplyService.submitDifficultyApply(smsStudentDifficultyTaskReq, user_id);
    }

    @ApiModelProperty(value = "家庭经济困难学生认定申请驳回提交")
    @PostMapping("/rejectSubmit")
    public ResponseResult submitDifficultyRejectApply(@RequestBody SmsStudentDifficultyApplyReq smsStudentDifficultyTaskReq,
                                                     HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentDifficultyApplyService.submitDifficultyRejectApply(smsStudentDifficultyTaskReq, user_id);
    }

    @ApiModelProperty(value = "家庭经济困难学生认定申请驳回")
    @PostMapping("/reject")
    public ResponseResult rejectDifficultyApply(@RequestBody SmsStudentDifficultyApplyReq smsStudentDifficultyTaskReq) {
        return smsStudentDifficultyApplyService.rejectDifficultyApply(smsStudentDifficultyTaskReq);
    }

    @ApiModelProperty(value = "获取本人家庭经济困难学生认定可申请列表")
    @GetMapping("/ownTaskList")
    public ResponseResult getOwnDifficultyTaskList(HttpServletRequest request,
                                                  @RequestParam(value = "search_str", required = false) String search_str,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentDifficultyApplyService.getOwnDifficultyTaskList(pageNum, pageSize, user_id,search_str);
    }

    @ApiModelProperty(value = "获取本人家庭经济困难学生认定申请历史")
    @GetMapping("/history")
    public ResponseResult getDifficultyApplyHistory(HttpServletRequest request,
                                                    @RequestParam(value = "search_str", required = false) String search_str,
                                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentDifficultyApplyService.getDifficultyApplyHistory(pageNum, pageSize, user_id,search_str);
    }

    @ApiModelProperty(value = "家庭经济困难学生认定填写获取")
    @GetMapping("/fill")
    public ResponseResult getSubmitDifficultyApply(HttpServletRequest request,
                                                  @RequestParam(value = "task_id") String task_id) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsStudentDifficultyApplyService.getSubmitDifficultyApply(task_id, user_id);
    }

    @ApiModelProperty(value = "家庭经济困难学生认定申请表详情")
    @GetMapping("/detail")
    public ResponseResult getDifficultyApplyDetail( @RequestParam(value = "apply_id") String apply_id) {
        return smsStudentDifficultyApplyService.getDifficultyApplyDetail(apply_id);
    }

    @ApiModelProperty(value = "家庭经济困难学生认定申请表下载")
    @GetMapping("/download")
    public ResponseResult exportDifficultyApply(@RequestParam(value = "apply_id") String apply_id, HttpServletResponse response) {
        return smsStudentDifficultyApplyService.exportDifficultyApply(apply_id,response);
    }
}

